package 反射;

import jdbc3.Brand;

import java.lang.reflect.Field;

/**
 * @Auther:lele
 * @Date:2025/3/13
 */
public class TestCar {
    public static void main(String[] args) throws Exception {
        Class<?> aClass = Class.forName("反射.Car");

        System.out.println("aClass = " + aClass);

        System.out.println("aClass.getConstructor() = " + aClass.getConstructor());
        System.out.println("aClass.getClasses() = " + aClass.getClasses());
        System.out.println("aClass.getName() = " + aClass.getName());
        Object o = aClass.newInstance();
        Field brand = aClass.getField("Brand");
        Object o1 = brand.get(o);
        System.out.println("o1 = " + o1);

//直接获取
        System.out.println("Car.class = " + Car.class);
//        通过对象获取
        Car car = new Car();
        System.out.println("car.getClass() = " + car.getClass());
//        类加载器获得反射
        ClassLoader classLoader = car.getClass().getClassLoader();
        Class<?> aClass1 = classLoader.loadClass("反射.Car");
        System.out.println("aClass1 = " + aClass1);


    }
}
